<?php

/**
 * This is the model class for table "cargo_details".
 */
class packing_list_packages_cargo_dimension extends cargo_details
{
	/**
	 * The followings are the available columns in table 'cargo_details':
	 * @var integer $id
	 * @var integer $cargo_id
	 * @var double $wt
	 * @var string $wt_type
	 * @var integer $qty
	 * @var string $qty_type
	 * @var double $length
	 * @var double $width
	 * @var double $height
	 * @var string $m3_type
	 * @var double $m3
	 */

	/**
	 * Returns the static model of the specified AR class.
	 * @return cargo_details the static model class
	 */
	public $qtytype = array('Ctn'=>'Ctn','Pcs'=>'Pcs','Pkg'=>'Pkg','Plt'=>'Plt','Case'=>'Case','Crate'=>'Crate','Drum'=>'Drum','Roll'=>'Roll','Bag'=>'Bag','Others'=>'Others');
	public $wttype = array('KG'=>'KG','Ton'=>'Ton','Lbs'=>'Lbs','Others','Others');
	public $m3type = array('M3'=>'M3');
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'cargo_details';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('foreign_key, qty', 'numerical', 'integerOnly'=>true),
			array('wt, m3, general', 'numerical'),
			array('wt_type, qty_type, m3_type', 'length', 'max'=>15),
			array('for_model', 'length', 'max'=>50),
			array('wt, qty, m3', 'required'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, cargo_id, wt, wt_type, qty, qty_type, length, width, height, m3_type, m3', 'safe', 'on'=>'search'),
		);
	}
	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}
	public function beforeSave(){
		$this->general=1;
		$this->for_model='packing_list_packages_cargo';
		return true;
	}
	public function beforeFind(){
		return true;
	}
	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function defaultScope(){
		return array(
           	'condition'=>"general=1 and for_model='packing_list_packages_cargo'",
        );
	}
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'cargo_id' => 'Cargo',
			'wt' => 'Weight',
			'wt_type' => 'Wt Type',
			'qty' => 'Quality',
			'qty_type' => 'Qty Type',
			'length' => 'Length',
			'width' => 'Width',
			'height' => 'Height',
			'm3_type' => 'M3 Type',
			'm3' => 'M3',
		);
	}
	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);

		$criteria->compare('cargo_id',$this->cargo_id);

		$criteria->compare('wt',$this->wt);

		$criteria->compare('wt_type',$this->wt_type,true);

		$criteria->compare('qty',$this->qty);

		$criteria->compare('qty_type',$this->qty_type,true);

		$criteria->compare('length',$this->length);

		$criteria->compare('width',$this->width);

		$criteria->compare('height',$this->height);

		$criteria->compare('m3_type',$this->m3_type,true);

		$criteria->compare('m3',$this->m3);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}